package com.xpu.pms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xpu.pms.comm.http.PageInfo;
import com.xpu.pms.comm.http.QueryPage;
import com.xpu.pms.comm.http.Respond;
import com.xpu.pms.entity.BaseGroupEntity;
import com.xpu.pms.mapper.BaseBuildingMapper;
import com.xpu.pms.entity.BaseBuildingEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.List;
/**
 * @author 徐立彬
 * @date 2019-11-22
 */
@RestController
@RequestMapping("base/building")
public class BaseBuildingController {
    @Autowired
    BaseBuildingMapper baseBuildingMapper;

    @RequestMapping("/page")
    public Respond page(@RequestBody QueryPage page) {
        long index = page.getPage().getIndex();
        long size = page.getPage().getSize();
        List<BaseBuildingEntity> list = baseBuildingMapper.selectBuildingList();
        int total = baseBuildingMapper.selectCount(new QueryWrapper<>());
        PageInfo pageInfo = new PageInfo((int)page.getPage().getIndex(),total,page.getPage().getSize());
        Respond res = new Respond().setPage(pageInfo).setData(list);
        return  res;
    }
    @RequestMapping("/all")
    public List<BaseBuildingEntity> all() {
        List<BaseBuildingEntity> list = baseBuildingMapper.selectList(new QueryWrapper<>());
        return list;
    }
    
    @RequestMapping("/add")
    public Respond add(@RequestBody BaseBuildingEntity entity) {
        baseBuildingMapper.insert(entity);
        return new Respond();
    }
    
    @RequestMapping("/update")
    public Respond update(@RequestBody BaseBuildingEntity entity) {
        baseBuildingMapper.updateById(entity);
        return new Respond();
    }
    
    @RequestMapping("/del")
    public Respond del(@RequestBody BaseBuildingEntity entity) {
        baseBuildingMapper.deleteById(entity.getId());
        return new Respond();
    }
}
